/*
 * signal.c
 *  
 * Mark Claypool, WPI
 * Fall 2011
 *
 * Show basic signal handler.
 */

#include <stdio.h>
#include <signal.h>

int n;

void InterruptHandler();
void InitHandler();

main(int argc, char **argv)
{

    n = 0;

    signal(SIGINT, InterruptHandler); /* signal 2, INT */
    signal(SIGHUP, InitHandler);      /* signal 1, HUP for Hanup */
    while (1) {
        n++;
        sleep(1);
    }
}

void InterruptHandler()
{
    printf("The current value of n is %d\n", n);
    exit(0);
}

void InitHandler()
{
    printf("Resetting the value of n to zero\n");
    n = 0;
}
